package net.cooltain.warhammer.running.window.panel;

import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.JLabel;

import net.cooltain.warhammer.framework.constant.ConstantPicture;
import net.cooltain.warhammer.running.entity.MotionPlayerZone;
import net.cooltain.warhammer.running.window.MainFrame;

/**
 * 默认规则：双方都可以看到对方的弃牌堆的每一张卡片
 * @author cooltian
 *
 */
public class PreviewCardLabel extends JLabel  {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -2045966061927030692L;
	
	private MotionPlayerZone player ; 	    // 显示这个卡片的玩家,不一定是拥有卡片的人
	private MainFrame        mainFrame ;   // 要预览的卡
	private BufferedImage    backCardImage; // 缓存图片:卡牌背面
	private BufferedImage    unfindImage;   // 缓存图片:找不到图片路径
	
	public PreviewCardLabel(MotionPlayerZone player,MainFrame mainFrame) {
		super();
		this.setDoubleBuffered(true);
		this.player = player;
		this.mainFrame = mainFrame;
		try {
			backCardImage = ImageIO.read(new File(ConstantPicture.PIC_CARD_BACK));
			unfindImage = ImageIO.read(new File(ConstantPicture.PIC_CARD_UNFIND));
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	
	public void paintComponent(Graphics g){
		super.paintComponent(g);
		if( mainFrame.previewCard!=null){			
			if( mainFrame.previewCard.checkVisiblePlayer(player)){		
				BufferedImage image = unfindImage;
				try {
					image = mainFrame.previewCard.cardEntity.getBufferedImage();
				} catch (Exception e) {
					// do nothing
				}
				g.drawImage(image, 0, 0, this.getWidth(), this.getHeight(), null);
			}else{
				g.drawImage(backCardImage, 0, 0, this.getWidth(), this.getHeight(), null);			
			}
		}
	}

}
